package CH01数组结构.LeetCode双指针;

public class LC11 {
    public int maxArea(int[] height) {
        int maxArea = 0;
        int l = 0;
        int r = height.length - 1;
        while (l < r) {
            if (height[l] <= height[r]) {
                int low = height[l];
                int area = (r - l) * low;
                maxArea = Math.max(area, maxArea);
                while (l < r && height[l] <= low) {
                    l++;
                }
            } else {
                int low = height[r];
                int area = (r - l) * low;
                maxArea = Math.max(area, maxArea);
                while (l < r && height[r] <= low) {
                    r--;
                }
            }
        }
        return maxArea;
    }
}